package com.wangchao.administrator.zenmechi.ui.stepactivity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wangchao.administrator.zenmechi.R;
import com.wangchao.administrator.zenmechi.bean.stepbean.StepIngredientsListsBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/18.
 */
public class MyAdapterForingredients extends BaseAdapter {

    private Context context;
    private List<StepIngredientsListsBean> lists;

    public MyAdapterForingredients(Context context, List<StepIngredientsListsBean> lists) {
        this.context = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int i) {
        return lists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null){
            view = LayoutInflater.from(context).inflate
                    (R.layout.step_ingredients_list_item, viewGroup, false);
            holder  = new ViewHolder(view);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }

        holder.tvLeft.setText(lists.get(i).getName());
        holder.tvRight.setText(lists.get(i).getQuantity());
        return view;
    }


    static class ViewHolder {
        @BindView(R.id.tv_left)
        TextView tvLeft;
        @BindView(R.id.tv_right)
        TextView tvRight;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
